package com.gz.mylife.app;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.Intent;
import android.graphics.Picture;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.gz.mylife.Define;
import com.gz.mylife.R;
import com.gz.mylife.adapter.AdvertFragment;
import com.gz.mylife.adapter.AdvertFragmentAdapter;
import com.gz.mylife.adapter.BaseAdapterHelper;
import com.gz.mylife.adapter.FragmentMallAdapter;
import com.gz.mylife.adapter.QuickAdapter;
import com.gz.mylife.app.keys.LoginDoorActivity;
import com.gz.mylife.app.keys.MainActivity;
import com.gz.mylife.http.AsyncHttpClient;
import com.gz.mylife.http.AsyncHttpResponseHandler;
import com.gz.mylife.http.RequestParams;
import com.gz.mylife.po.ActivitiesInfoWrapper;
import com.gz.mylife.util.ImageUtils;
import com.gz.mylife.util.PrefUtils;
import com.gz.mylife.util.ViewUtils;
import com.gz.mylife.widget.LoadingCover;
import com.gz.mylife.widget.PageIndicator;
import com.gz.mylife.widget.LoadingCover.OnLoadingCoverRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.zl.smartmall.library.IGZAddress;
import com.zl.smartmall.library.ISmartMall;
import com.zl.smartmall.library.listener.ActivitiesListener;
import com.zl.smartmall.library.po.ActivitiesBrandIconInfo;
import com.zl.smartmall.library.po.ActivitiesCommoditiesInfo;
import com.zl.smartmall.library.po.ActivitiesInfoType;
import com.zl.smartmall.library.po.ActivitiesLatestNoticeInfo;
import com.zl.smartmall.library.po.ActivitiesThemeMarketInfo;
import com.zl.smartmall.library.po.AdvertInfo;
import com.zl.smartmall.library.po.BaseActivitiesInfo;
import com.zl.smartmall.library.po.LoginData;
import com.zl.smartmall.library.util.Constants;
import com.zl.smartmall.library.util.CrashHandler;
import com.zl.smartmall.library.util.PreferenceModel;
import com.zl.smartmall.library.util.ShareUtil;

/**
 * 商城首页
 * 
 * @author 陈希然
 * 
 */
public class FragmentMall extends Fragment implements OnPageChangeListener,
OnRefreshListener<ListView>, OnItemClickListener,
OnLoadingCoverRefreshListener, OnClickListener {

	private static final String TAG = FragmentMall.class.getSimpleName();

	private static final int LOOP_ORIENTATION_FORWARD = 0;
	private static final int LOOP_ORIENTATION_BACK = 1;
	private static final int LOOP_DELAYED = 2000;

	private int mCurrentPageAdvert;
	private int mLoopOrientation = LOOP_ORIENTATION_FORWARD;
	private int mPage = 1;
	private ActivitiesListener mActivitiesListener;
	private AdvertFragmentAdapter mAdvertFragmentAdapter;
	private Context mContext;
	private DisplayImageOptions mIconOption;
	private FragmentMallAdapter mFragmentMallAdapter;
	private Handler mHandler;
	private QuickAdapter<ActivitiesBrandIconInfo> mClassifyAdapter;

	private GridView mGridViewClassify;
	private LoadingCover mLoadingCover;
	private PageIndicator mPageIndicator;
	private PullToRefreshListView mListView;
	private ViewPager mViewPager;
	private View mConvertView;
	private View mHeadView;
	public static String userpoint;//当前登录用户的积分
	public static String msgurl;//当前登录用户接收到的物业通知
	private String phone_num;
	private String phone_password;
	private String phone_sn;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		CrashHandler.d(TAG, TAG + " onCreate");
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		CrashHandler.d(TAG, TAG + " onCreateView");
		if (mConvertView == null) {
			CrashHandler.d(TAG, "convertView is null, init the whole elements");
			mConvertView = inflater.inflate(R.layout.fragment_mall, container,
					false);
			init(inflater);
		}
		// ((BaseActionBarActivity) getActivity()).mActionBar.setTitle("营养专栏");

		return mConvertView;
	}

	@Override
	public void onDetach() {
		// TODO Auto-generated method stub
		super.onDetach();
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		CrashHandler.d(TAG, TAG + " onDestroy");
	}

	@Override
	public void onDestroyView() {
		// TODO Auto-generated method stub
		super.onDestroyView();
		CrashHandler.d(TAG, TAG + " onDestroyView");
		((ViewGroup) mConvertView.getParent()).removeView(mConvertView);
	}

	@Override
	public void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		CrashHandler.d(TAG, TAG + " onPause");
	}

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		CrashHandler.d(TAG, TAG + " onResume");
		// mGridAdapter.notifyDataSetChanged();
	}

	@Override
	public void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		mHandler.postDelayed(mLoopPlaybackTask, LOOP_DELAYED);
	}

	@Override
	public void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		mHandler.removeCallbacks(mLoopPlaybackTask);
	}

	@Override
	public void onPageScrollStateChanged(int arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onPageSelected(int position) {
		// TODO Auto-generated method stub
		mCurrentPageAdvert = position;
		switch (mLoopOrientation) {
		case LOOP_ORIENTATION_FORWARD:
			if (mCurrentPageAdvert == mAdvertFragmentAdapter.getCount() - 1
			|| mCurrentPageAdvert > mAdvertFragmentAdapter.getCount()) {// 最后一页，或者是早期数据多于最新数据
				mLoopOrientation = LOOP_ORIENTATION_BACK;
			}
			break;

		case LOOP_ORIENTATION_BACK:
			if (mCurrentPageAdvert == 0) {
				mLoopOrientation = LOOP_ORIENTATION_FORWARD;
			}
			break;
		}
	}

	@Override
	public void onRefresh(PullToRefreshBase<ListView> refreshView) {
		// TODO Auto-generated method stub
		mPage = 1;
		ISmartMall.getInstance().getHomePage(
				IGZAddress.getInstance().getCurrentCommunityID(),IGZAddress.getInstance().getCurrentHouseid(), mPage,
				mActivitiesListener);
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		// TODO Auto-generated method stub
		CrashHandler.d(TAG,
				"viewType" + mFragmentMallAdapter.getItemViewType((int) id));
		if (mFragmentMallAdapter.getItemViewType((int) id) == ActivitiesInfoType.TYPE_COMMODITIES_ITEM) {
			ActivitiesCommoditiesInfo activitiesCommoditiesInfo = (ActivitiesCommoditiesInfo) mFragmentMallAdapter
					.getItem((int) id);
			Intent intent = new Intent(mContext, ProductDetail.class);
			intent.putExtra("productId",
					activitiesCommoditiesInfo.getProductId());
			intent.putExtra("shopId", activitiesCommoditiesInfo.getShopId());
			intent.putExtra("mBrandId", activitiesCommoditiesInfo.getBrandId());
			startActivity(intent);
		}

	}

	@Override
	public void onLoadingCoverRefresh() {
		// TODO Auto-generated method stub
		ISmartMall.getInstance().getHomePage(
				IGZAddress.getInstance().getCurrentCommunityID(), IGZAddress.getInstance().getCurrentHouseid(),mPage,
				mActivitiesListener);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.layout_theme_1:
		case R.id.layout_theme_2:
		case R.id.layout_theme_3:
		case R.id.layout_theme_4:
		case R.id.layout_theme_5:
			if (v.getTag() != null) {
				Intent intent = new Intent(mContext,
						FragmentMallBrandedProductsActivity.class);
				intent.putExtra("name",
						((ActivitiesThemeMarketInfo) v.getTag()).getName());
				intent.putExtra("brandId", ((ActivitiesThemeMarketInfo) v
						.getTag()).getActivitiesId());
				startActivity(intent);
			}
			break;

		case R.id.tv_actionbar_title:
			startActivity(new Intent(mContext, MyCommunityActivity.class));
			break;
		}
	}

	public void autoRefresh() {
		onRefresh(mListView);
	}

	private QuickAdapter<ActivitiesBrandIconInfo> buildClassifyAdapter() {
		// https://github.com/maurycyw/StaggeredGridView瀑布流
		return new QuickAdapter<ActivitiesBrandIconInfo>(mContext,
				R.layout.fragment_mall_head_classify_item,
				new ArrayList<ActivitiesBrandIconInfo>()) {

			@Override
			protected void convert(BaseAdapterHelper helper,
					ActivitiesBrandIconInfo item) {
				// TODO Auto-generated method stub
				if (item.getActivitiesId() != -1) {
					helper.setImageUrl(R.id.iv_activities_icon, item.getIcon(),
							mIconOption).setText(R.id.tv_activities_title,
									item.getName());
				} else {
					helper.setImageUrl(R.id.iv_activities_icon,
							R.drawable.ic_contact_selector).setText(
									R.id.tv_activities_title, "联系物业");
				}
			}

		};
	}

	private void init(LayoutInflater inflater){
		mContext = getActivity().getApplicationContext();
		mClassifyAdapter = buildClassifyAdapter();
		mFragmentMallAdapter = new FragmentMallAdapter<BaseActivitiesInfo>(mContext, new ArrayList<BaseActivitiesInfo>());
		mHandler = new Handler();
		//		mHotSaleGoodsAdapter = buildHotSaleGoodsAdapter();
		mIconOption = ImageUtils.buildTransparentOptions();
		mAdvertFragmentAdapter = new AdvertFragmentAdapter(getChildFragmentManager());
		initListener();

		((BaseActivity) getActivity()).mActionbarTitle.setOnClickListener(this);
		mHeadView = inflater.inflate(R.layout.fragment_mall_head, null);
		mGridViewClassify = (GridView) mHeadView.findViewById(R.id.gridview_classify);
		mGridViewClassify.setAdapter(mClassifyAdapter);
		mGridViewClassify.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				if(mClassifyAdapter.getItem((int) id).getActivitiesId() == -1) {
					startActivity(new Intent(mContext, ContactTenement.class));

				}else {
					if("1".equals(mClassifyAdapter.getItem((int) id).getIcontype())){//活动商品
						Intent intent = new Intent(mContext, FragmentMallBrandedProductsActivity.class);
						intent.putExtra("name", mClassifyAdapter.getItem((int) id).getName());
						intent.putExtra("brandId", mClassifyAdapter.getItem((int) id).getActivitiesId());
						startActivity(intent);	
					}else if ("2".equals(mClassifyAdapter.getItem((int) id).getIcontype())) {//系统通知
						Intent intent = new Intent(mContext, EventActivity.class);
						intent.putExtra("name", mClassifyAdapter.getItem((int) id).getName());
						intent.putExtra("brandId", mClassifyAdapter.getItem((int) id).getActivitiesId());
						intent.putExtra("content", mClassifyAdapter.getItem((int) id).getContent());
						startActivity(intent);
					}else if("3".equals(mClassifyAdapter.getItem((int) id).getIcontype())){//点击链接到联系物业
						Intent intent = new Intent(mContext, ContactTenement.class);
						startActivity(intent);
					}else if ("4".equals(mClassifyAdapter.getItem((int) id).getIcontype())){//链接到在线缴费的网页
						Intent newsIntent = new Intent(getActivity(), BrowserPay.class);
						newsIntent.putExtra("url", mClassifyAdapter.getItem((int) id).getContent());
						newsIntent.putExtra("title", "在线缴费");
						startActivity(newsIntent);
					}else if ("5".equals(mClassifyAdapter.getItem((int) id).getIcontype())){//链接到商城搜索
						Intent intent = new Intent(mContext, FragmentAssortment.class);
						intent.putExtra("name", mClassifyAdapter.getItem((int) id).getName());
						intent.putExtra("brandId", mClassifyAdapter.getItem((int) id).getActivitiesId());
						startActivity(intent);
					}/*else if ("6".equals(mClassifyAdapter.getItem((int) id).getIcontype())){//链接到考拉门禁
						autoLogin();
					}*/else if ("7".equals(mClassifyAdapter.getItem((int) id).getIcontype())){
						Intent newsIntent = new Intent(getActivity(), BrowserPay.class);
						newsIntent.putExtra("url", mClassifyAdapter.getItem((int) id).getContent()+"?storeuser_id="+PreferenceModel.getInt(Constants.PREFERENCE_KEY_UID,-1));
						newsIntent.putExtra("title", "预约洗衣");
						startActivity(newsIntent);
					}
				}
			}
		});

		mViewPager = (ViewPager) mHeadView.findViewById(R.id.pager);
		mViewPager.setAdapter(mAdvertFragmentAdapter);
		ViewUtils.SmoothViewPagerScrollerMaker(mViewPager);
		mPageIndicator = (PageIndicator) mHeadView.findViewById(R.id.page_indicator);
		mPageIndicator.setViewPage(mViewPager);
		mPageIndicator.setOnPageChangeListener(this);

		mListView = (PullToRefreshListView) mConvertView.findViewById(R.id.list);
		mListView.getRefreshableView().addHeaderView(mHeadView);
		//		mPullList.setAdapter(mHotSaleGoodsAdapter);
		mListView.setAdapter(mFragmentMallAdapter);
		mListView.setOnRefreshListener(this);
		mListView.setOnItemClickListener(this);

		mLoadingCover = (LoadingCover) mConvertView.findViewById(R.id.layout_loading_cover);
		mLoadingCover.setOnLoadingCoverRefreshListener(this);

		onLoadingCoverRefresh();
	}

	private void initListener() {
		mActivitiesListener = new ActivitiesListener() {

			@Override
			public void onResponseFailed() {
				// TODO Auto-generated method stub
				if (mListView.isRefreshing()) {
					mListView.getLoadingLayoutProxy().refreshFailed();
				}
				mLoadingCover.onRefreshFailed();
				
				if (mListView.isRefreshing()) {
					mListView.getLoadingLayoutProxy().refreshFailed();
				}
				String jsonobject = ShareUtil.getstringvalue(mContext, "mylife");
				try {
					JSONObject object = new JSONObject(jsonobject);
					userpoint = object.getString("user_point");
					msgurl = object.getString("message_url");
					List<AdvertInfo> advertInfo = AdvertInfo.parseArray(object.getJSONArray("brandsad"), Constants.ADVERT_AFFILIATION_ACTIVITIES);
					List<ActivitiesBrandIconInfo> activitiesBrandIconInfos = ActivitiesBrandIconInfo.parse(object.getJSONArray("activitiesIcon"), ActivitiesInfoType.TYPE_CLASSIFY);
					List<ActivitiesThemeMarketInfo> activitiesThemeMarketInfos = ActivitiesThemeMarketInfo.parse(object.getJSONArray("themeActsList")); 
					List<ActivitiesBrandIconInfo> activitiesBrandIconInfos2 = ActivitiesBrandIconInfo.parse(object.getJSONArray("activitiesList"), ActivitiesInfoType.TYPE_RECOMMEND_MERCHANT); 
					List<ActivitiesCommoditiesInfo> activitiesCommoditiesInfos = ActivitiesCommoditiesInfo.parse(object.getJSONArray("hotProduct"));
					List<ActivitiesLatestNoticeInfo> activitiesLatestNoticeInfos = ActivitiesLatestNoticeInfo.parse(object.getJSONArray("notices_list"));
					init(advertInfo,activitiesBrandIconInfos,activitiesThemeMarketInfos,activitiesBrandIconInfos2,activitiesCommoditiesInfos,activitiesLatestNoticeInfos,userpoint,msgurl);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				
			}

			@Override
			public void onOffline() {
				// TODO Auto-generated method stub
				mLoadingCover.onRefreshFailed();
			}

			@Override
			public void onNoMoreData() {
				// TODO Auto-generated method stub
				if (mListView.isRefreshing()) {
					mListView.getLoadingLayoutProxy().refreshSuccess();
				}
				mLoadingCover.onRefreshFailed(Define.MSG_NO_MORE_DATA);
			}

			@Override
			public void onResponseSuccess(List<AdvertInfo> advertInfos,
					List<ActivitiesBrandIconInfo> classify,
					List<ActivitiesThemeMarketInfo> activitiesThemeMarketInfos,
					List<ActivitiesBrandIconInfo> activitiesBrandIconInfos,
					List<ActivitiesCommoditiesInfo> activitiesCommoditiesInfos,
					List<ActivitiesLatestNoticeInfo> activitiesLatestNoticeInfos,String point,String json,String messageurl) {
				ShareUtil.setstringvalue(mContext, "mylife", json);
				if (point != null && !"".equals(point)) {
					FragmentPersonal.tvpoint.setText("积分:"+point);
				}else {
					FragmentPersonal.tvpoint.setText("积分:"+0);
				}
				msgurl = messageurl;
				init(advertInfos,classify,activitiesThemeMarketInfos,activitiesBrandIconInfos,activitiesCommoditiesInfos,activitiesLatestNoticeInfos,point,messageurl);
			}

			@Override
			public void onNoNetWork() {
				// TODO Auto-generated method stub
				if (mListView.isRefreshing()) {
					mListView.getLoadingLayoutProxy().refreshFailed();
				}
				String jsonobject = ShareUtil.getstringvalue(mContext, "mylife");
				try {
					JSONObject object = new JSONObject(jsonobject);
					userpoint = object.getString("user_point");
					msgurl = object.getString("message_url");
					List<AdvertInfo> advertInfo = AdvertInfo.parseArray(object.getJSONArray("brandsad"), Constants.ADVERT_AFFILIATION_ACTIVITIES);
					List<ActivitiesBrandIconInfo> activitiesBrandIconInfos = ActivitiesBrandIconInfo.parse(object.getJSONArray("activitiesIcon"), ActivitiesInfoType.TYPE_CLASSIFY);
					List<ActivitiesThemeMarketInfo> activitiesThemeMarketInfos = ActivitiesThemeMarketInfo.parse(object.getJSONArray("themeActsList")); 
					List<ActivitiesBrandIconInfo> activitiesBrandIconInfos2 = ActivitiesBrandIconInfo.parse(object.getJSONArray("activitiesList"), ActivitiesInfoType.TYPE_RECOMMEND_MERCHANT); 
					List<ActivitiesCommoditiesInfo> activitiesCommoditiesInfos = ActivitiesCommoditiesInfo.parse(object.getJSONArray("hotProduct"));
					List<ActivitiesLatestNoticeInfo> activitiesLatestNoticeInfos = ActivitiesLatestNoticeInfo.parse(object.getJSONArray("notices_list"));
					init(advertInfo,activitiesBrandIconInfos,activitiesThemeMarketInfos,activitiesBrandIconInfos2,activitiesCommoditiesInfos,activitiesLatestNoticeInfos,userpoint,msgurl);
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
	}

	private void refreshAdvert(List<AdvertInfo> advertInfos) {
		CrashHandler.d(TAG, "advert size = " + advertInfos.size());
		List<AdvertFragment> fragments = new ArrayList<AdvertFragment>();
		for (int i = 0; i < advertInfos.size(); i++) {
			AdvertFragment fragment = AdvertFragment.newInstance(
					advertInfos.get(i), advertInfos.get(i).getPicture());
			fragments.add(fragment);
		}
		if (advertInfos.size() > 1) {
			mPageIndicator.setVisibility(View.VISIBLE);
		} else {
			mPageIndicator.setVisibility(View.GONE);
		}

		mAdvertFragmentAdapter.clear();
		mAdvertFragmentAdapter.addAll(fragments);
		mAdvertFragmentAdapter.notifyDataSetChanged();
		mPageIndicator.notifyDataSetChanged();
	}

	private Runnable mLoopPlaybackTask = new Runnable() {

		@Override
		public void run() {
			if (mAdvertFragmentAdapter.getCount() > 0) {
				// CrashHandler.d(TAG, "循环广告" + mCurrentPageAdvert);
				switch (mLoopOrientation) {
				case LOOP_ORIENTATION_BACK:
					mViewPager.setCurrentItem(mCurrentPageAdvert--);
					break;

				case LOOP_ORIENTATION_FORWARD:
					mViewPager.setCurrentItem(mCurrentPageAdvert++);
					break;
				}
				mHandler.postDelayed(mLoopPlaybackTask, LOOP_DELAYED);
			}
		}
	};

	
		private void autoLogin() {

			phone_num = PrefUtils.getStrPrefData(getActivity(), "phone_num", "");
			if (phone_num.equals("")) {

				new Thread(){
					@Override
					public void run() {
						super.run();
						try {
							Intent i = new Intent(getActivity(), LoginDoorActivity.class);
							startActivity(i);
						} catch (Exception e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}

					}
				}.start();
			}else{
				phone_password = PrefUtils.getStrPrefData(getActivity(), "phone_password", "");
				phone_sn = PrefUtils.getStrPrefData(getActivity(), "phone_sn", "");
				String url = Constants.LOGIN_URL;
				AsyncHttpClient httpClient=new AsyncHttpClient();
				RequestParams params=new RequestParams();
				params.put("phone_num", phone_num);
				params.put("phone_password", phone_password);
				params.put("phone_sn", phone_sn);
				//这个是get方法请求，自己调配，2者写一就行
				httpClient.get(url , params,new AsyncHttpResponseHandler(){

					@Override
					public void onSuccess(String content) {
						super.onSuccess(content);
						Gson gson = new Gson();
						LoginData mLoginData = gson.fromJson(content, LoginData.class);
						//验证成功
						if(mLoginData.ref==0){
							Toast.makeText(getActivity(),mLoginData.msg, 0).show();
							new Thread(){
								public void run() {
									try {
									} catch (Exception e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
									}
									Intent i = new Intent(getActivity(),MainActivity.class);
									startActivity(i);
								};
							}.start();
						}else {

							Toast.makeText(getActivity(),mLoginData.msg, 0).show();
							new Thread(){
								public void run() {
									try {
										Intent i = new Intent(getActivity(),LoginDoorActivity.class);
										startActivity(i);
									} catch (Exception e) {
										// TODO Auto-generated catch block
										e.printStackTrace();
									}
								}
							}.start();

						}
					}

					@Override
					public void onFailure(Throwable error, String content) {
						super.onFailure(error, content);

//						Toast.makeText(getActivity(),"请求失败...", 0).show();
						new Thread(){
							public void run() {
								try {
								} catch (Exception e) {
									// TODO Auto-generated catch block
									e.printStackTrace();
								}finally{
									Intent i = new Intent(getActivity(),MainActivity.class);
									startActivity(i);
								}
							};
						}.start();
					}
				});
			}

		}

		private void init(List<AdvertInfo> advertInfos,
				List<ActivitiesBrandIconInfo> classify,
				List<ActivitiesThemeMarketInfo> activitiesThemeMarketInfos,
				List<ActivitiesBrandIconInfo> activitiesBrandIconInfos,
				List<ActivitiesCommoditiesInfo> activitiesCommoditiesInfos,
				List<ActivitiesLatestNoticeInfo> activitiesLatestNoticeInfos,String point,String url){
			// TODO Auto-generated method stub
			refreshAdvert(advertInfos);
			mFragmentMallAdapter.clear();
			// 最新公告
			if (activitiesLatestNoticeInfos.size() > 0) {
				ActivitiesInfoWrapper<BaseActivitiesInfo> activitiesInfoWrapper = new ActivitiesInfoWrapper<BaseActivitiesInfo>();
				activitiesInfoWrapper
				.setActivitiesInfoType(ActivitiesInfoType.TYPE_NOTICE);
				for (int i = 0; i < activitiesLatestNoticeInfos.size(); i++) {
					activitiesInfoWrapper
					.addDataset(activitiesLatestNoticeInfos.get(i));
				}
				mFragmentMallAdapter.add(activitiesInfoWrapper);
			}
			// 主题市场adapter
			if (activitiesThemeMarketInfos.size() > 0) {
				ActivitiesInfoWrapper<BaseActivitiesInfo> activitiesInfoWrapper = new ActivitiesInfoWrapper<BaseActivitiesInfo>();
				activitiesInfoWrapper
				.setActivitiesInfoType(ActivitiesInfoType.TYPE_THEME_MARKET);
				for (ActivitiesThemeMarketInfo activitiesThemeMarketInfo : activitiesThemeMarketInfos) {
					activitiesInfoWrapper
					.addDataset(activitiesThemeMarketInfo);
				}
				mFragmentMallAdapter.add(activitiesInfoWrapper);
			}
			// 推荐商家
			if (activitiesBrandIconInfos.size() > 0) {

				int len = activitiesBrandIconInfos.size() % 3;
				if (len != 0) {
					for (int i = 0; i < 3 - len; i++) {
						ActivitiesBrandIconInfo activitiesBrandIconInfo = new ActivitiesBrandIconInfo();
						activitiesBrandIconInfo.setActivitiesId(-1);// 显示空白格
						activitiesBrandIconInfos
						.add(activitiesBrandIconInfo);
					}
				}
				ActivitiesInfoWrapper<BaseActivitiesInfo> activitiesInfoWrapper = new ActivitiesInfoWrapper<BaseActivitiesInfo>();
				activitiesInfoWrapper
				.setActivitiesInfoType(ActivitiesInfoType.TYPE_RECOMMEND_MERCHANT);
				for (int i = 0; i < activitiesBrandIconInfos.size(); i++) {
					activitiesInfoWrapper
					.addDataset(activitiesBrandIconInfos.get(i));
				}
				mFragmentMallAdapter.add(activitiesInfoWrapper);

			}

			// 热销商品adapter
			if (activitiesCommoditiesInfos.size() > 0) {
				// 先添加头, 然后添加item
				ActivitiesInfoWrapper<BaseActivitiesInfo> activitiesInfoWrapper = new ActivitiesInfoWrapper<BaseActivitiesInfo>();
				activitiesInfoWrapper
				.setActivitiesInfoType(ActivitiesInfoType.TYPE_COMMODITIES);
				mFragmentMallAdapter.add(activitiesInfoWrapper);
				mFragmentMallAdapter.addAll(activitiesCommoditiesInfos);
			}
			mFragmentMallAdapter.notifyDataSetChanged();

			ActivitiesBrandIconInfo classifyActivitiesBrandIconInfo = new ActivitiesBrandIconInfo();
			classifyActivitiesBrandIconInfo.setActivitiesId(-1);
			classify.add(classifyActivitiesBrandIconInfo);
			mClassifyAdapter.clear();
			mClassifyAdapter.addAll(classify);
			// mHotSaleGoodsAdapter.clear();
			// mHotSaleGoodsAdapter.addAll(activitiesCommoditiesInfos);

			if (mListView.isRefreshing()) {
				mListView.getLoadingLayoutProxy().refreshSuccess();
			}
			mLoadingCover.onRefreshSuccess();

		};

			

}
